package es.cea.web;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/LibroEdit")
public class LibroEdit extends HttpServlet {
	private static final long serialVersionUID = 1L;
           
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		PrintWriter writer = response.getWriter();
		writer.print("<html><body>");
		String parameter = request.getParameter("id");
		
		try  
        {  
        	Class.forName("com.mysql.jdbc.Driver");  
        	Connection conexion = DriverManager.getConnection ("jdbc:mysql://localhost/libreria","root", "root");        
        	Statement s = conexion.createStatement();
        	ResultSet rs = s.executeQuery("SELECT * FROM libros WHERE id=" + parameter);
        	rs.next();        	
        	writer.write("<form  method=get action=LibroEditProcess>");
        	writer.write("<input type=text value="+rs.getString(2)+" name=nombre>");
        	writer.write("<input type=hidden value="+rs.getString(1)+" name=id>");
        	writer.write("<input type=submit value=aceptar>");
        	writer.write("</form>");
        	writer.print("</body></html>");
        } catch (Exception e)  
        {  
           e.printStackTrace();  
        } 
	}
}
